package com.example.zhaoping.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhaoping.domain.Companies;
import com.example.zhaoping.domain.ResponseResult;
import com.example.zhaoping.mapper.CompaniesMapper;
import com.example.zhaoping.service.ICompaniesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhaoping.vo.PageVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author czx
 * @since 2024-12-24
 */
@Service
public class CompaniesServiceImpl extends ServiceImpl<CompaniesMapper, Companies> implements ICompaniesService {
    //==========================分页查询公司列表================================================
    @Override
    public ResponseResult companiesList(Integer pageNum, Integer pageSize, String name) {
        if (pageNum == null || pageNum < 1) {
            pageNum = 1;
        }
        if (pageSize == null || pageSize < 1) {
            pageSize = 10;
        }
        LambdaQueryWrapper<Companies> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(name),Companies::getName,name);

        Page<Companies> page = new Page<>(pageNum,pageSize);
        Page<Companies> CompaniesPage = page(page, queryWrapper);
        List<Companies> records = CompaniesPage.getRecords();

        PageVo pageVo = new PageVo(records, CompaniesPage.getTotal());
        return ResponseResult.okResult(pageVo);




    }
}
